package com.sokal.easycare.modules.position.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sokal.easycare.common.persistence.Page;
import com.sokal.easycare.common.service.CrudService;
import com.sokal.easycare.common.utils.StringUtils;
import com.sokal.easycare.modules.position.dao.DutyApplyDao;
import com.sokal.easycare.modules.position.entity.DutyApply;
import com.sokal.easycare.modules.sys.dao.UserDao;
import com.sokal.easycare.modules.sys.entity.MainUser;
import com.sokal.easycare.modules.sys.utils.DictUtils;

/**
 * 岗位申请Service
 * @author yangmin
 * @version 2017-04-24
 */
@Service
@Transactional(readOnly = true)
public class DutyApplyService extends CrudService<DutyApplyDao, DutyApply> {

	@Autowired
	private UserDao userDao;
	
	public DutyApply get(String id) {
		return super.get(id);
	}
	
	public List<DutyApply> findList(DutyApply dutyApply) {
		return super.findList(dutyApply);
	}
	
	public Page<DutyApply> findPage(Page<DutyApply> page, DutyApply dutyApply) {
		return super.findPage(page, dutyApply);
	}
	
	@Transactional(readOnly = false)
	public void save(DutyApply dutyApply) {
		super.save(dutyApply);
		String pass = DictUtils.getDictValue("审核通过","duty_apply", "0");
		
		MainUser user = dutyApply.getUser();
		//审核通过更改用户类型 status 4角色申请提交5审核通过6审核失败
		if(StringUtils.isNoneEmpty(pass) && pass.equals(dutyApply.getState()))
		{
			user.setUserType(dutyApply.getDutyType());
			user.setStatus("5");
			userDao.updateStatus(user);
			userDao.updateUserType(user);
		}else
		{
			user.setStatus("6");
			userDao.updateStatus(user);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(DutyApply dutyApply) {
		super.delete(dutyApply);
	}
	
}